<template>
	<view class="consumption">
		<block v-if="listData.length == 0">
			<view class="all_empty">
				<u-empty mode="data" text="列表为空"></u-empty>
			</view>
		</block>
		<block v-else>
			<u-cell-group>
				<block v-for="(item, index) in listData" :key="index">
					<u-cell :title="item.goods_name" label="2022-09-08" :value="item.price">
						<view slot="label" class="grey_color size24 desc">
							<text v-if="item.order_time > 0">{{ $u.timeFormat(item.order_time * 1000, 'yyyy年mm月dd日') }}</text>
							<text v-else>购买很久了</text>
						</view>
					</u-cell>
				</block>
			</u-cell-group>
		</block>
		<u-loadmore v-if="listData.length >= queryForm.limit" :status="status" :loading-text="loadingText" :loadmore-text="loadmoreText" :nomore-text="nomoreText" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			queryForm: {
				id: 0,
				limit: 10,
				page: 1
			},
			listData: [],
			status: 'loadmore',
			loadingText: '努力加载中',
			loadmoreText: '轻轻上拉',
			nomoreText: '实在没有了'
		};
	},
	onLoad({ id }) {
		if (!id) {
			this.$goBack();
		}
		this.queryForm.id = id;
		this.$initConfig().then(() => {
			this.getInfo();
		});
	},
	onReachBottom() {
		if (this.status != 'nomore') {
			this.queryForm.page++;
			this.getInfo(true);
		}
	},
	methods: {
		getInfo(is_add = false) {
			let _this = this;
			this.status = 'loading';
			_this
				.$http('order/getUserOrderListInfo', {
					...this.queryForm
				})
				.then((res) => {
					if (res.code) {
						if (is_add) {
							this.listData = _this.listData.concat(res.data.data);
						} else {
							_this.listData = res.data.data;
						}
						if (_this.listData.length >= res.data.total) {
							this.status = 'nomore';
						} else {
							this.status = 'loadmore';
						}
					}
				});
		}
	}
};
</script>

<style lang="scss" scoped>
.consumption {
	background: #fff;
}
.desc {
	marign-top: 20rpx;
}
</style>
